<!-- 操作日志页面 -->
<template>
  <div>
    <div class="content-box">
      <div class="left-box">
        <div class="title-box">操作日志</div>
        <div class="search-wrap">
          <el-date-picker v-model="dateRangeList" class="search-date-box" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="operationLog" />
          <div class="search-input-box">
            <img class="search-icon" src="@/assets/images/home/search-icon.png" alt="" />
            <input class="input" v-model="searchKeyword" type="text" placeholder="搜索操作人" @blur="operationLog" />
          </div>
        </div>
        <div class="table-list-box">
          <el-table v-loading="loading" element-loading-text="加载中..." :data="tableData" border :height="520">
            <el-table-column align="center" prop="id" label="操作ID" />
            <el-table-column align="center" prop="clerk_name" label="操作人" />
            <el-table-column align="center" prop="ip" label="IP地址" />
            <el-table-column align="center" prop="action" label="操作内容" />
            <el-table-column align="center" prop="params" label="操作参数" />
            <el-table-column align="center" prop="create_time" label="操作时间" />
          </el-table>
        </div>
        <div class="desc-btn-box">
          <div class="table-total" v-show="total > 0">
            <span>共{{ total }}条</span>
            <div>
              <Pagination v-show="total > 0" :total="total" v-model:page="searchParam.page" v-model:limit="searchParam.limit" @pagination="operationLog" :pageSizes="[15, 30, 45, 100]" />
            </div>
          </div>
          <div class="btn-box">
            <div class="update-status" @click="handleBack">返回</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { operationLog as fetchOperationLog } from '@/api/time'
import Pagination from '@/components/Pagination/Index.vue'

const router = useRouter()
const dateRangeList = ref([])
const searchKeyword = ref('')
const searchParam = reactive({ page: 1, limit: 15 })
const tableData = ref([])
const total = ref(0)
const loading = ref(false)

function operationLog() {
  loading.value = true
  let start_time = ''
  let end_time = ''
  if (dateRangeList.value && dateRangeList.value.length > 0) {
    start_time = dateRangeList.value[0] + ' 00:00:00'
    end_time = dateRangeList.value[1] + ' 23:59:59'
  }
  fetchOperationLog({ startTime: start_time, endTime: end_time, search: searchKeyword.value, page: searchParam.page, limit: searchParam.limit }).then(res => {
    tableData.value = res.data.list.data
    total.value = res.data.list.total
    loading.value = false
  }).finally(() => {
    loading.value = false
  })
}

function handleBack() { router.back() }

operationLog()
</script>

<style lang="scss" scoped>
::v-deep {
  .el-table {
    border-radius: 12px;
  }
  .el-table__body-wrapper {
    height: 580px;
    overflow-y: auto;
  }
  //滚动条整体的大小
  .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px !important;
    height: 0 !important;
  }
  //滚动条里滑动的滑块
  .el-table__body-wrapper::-webkit-scrollbar-thumb {
    height: 200px !important;
    background: #d2d2d2 !important;
    border-radius: 3px !important;
  }
  //滚动条底层样式
  .el-table__body-wrapper::-webkit-scrollbar-track {
    display: none !important;
  }
  .el-table th.el-table__cell {
    background: #a85b62;
    color: #fff !important;
  }
  .el-input__inner {
    border-radius: 12px;
  }
}
.content-box {
  display: flex;
  align-items: flex-start;
  .left-box {
    width: 1600px;
    height: 986px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 3px 0px 24px 0px rgba(0, 0, 0, 0.16);
    box-sizing: border-box;
    .title-box {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 88px;
      background: #f4f4f4;
      border-radius: 20px 20px 0px 0px;
      font-size: 20px;
      font-family: PingFang SC, PingFang SC-Bold;
      font-weight: 700;
      text-align: center;
      color: #333333;
    }
    .table-list-box {
      padding: 20px 50px 0 50px;
    }
    .search-wrap {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 88px;
      box-sizing: border-box;
      padding: 0 30px;
      box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.04);
      // .search-date-box {
      //   width: 300px;
      //   height: 46px;
      //   border-radius: 25px;
      //   box-sizing: border-box;
      //   padding-left: 20px;
      // }
      .search-input-box {
        width: 260px;
        height: 46px;
        border: 1px solid #d2d2d2;
        border-radius: 25px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        padding-left: 20px;
        .search-icon {
          flex-shrink: 0;
          width: 24px;
          height: 24px;
        }
        .input {
          border: none;
          outline: none;
          width: 180px;
          font-size: 16px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: 400;
          text-align: left;
          color: #333333;
          margin-left: 10px;
        }
      }
    }
    .desc-btn-box {
      display: flex;
      flex-direction: column;
      // align-items: center;
      // justify-content: space-between;
      margin-top: 40px;
      padding: 0px 50px;
      gap: 20px;
      box-sizing: border-box;
      .desc {
        font-size: 14px;
        font-family: PingFang SC, PingFang SC-Regular;
        font-weight: 400;
        text-align: left;
        color: #333333;
      }
      .table-total {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      .btn-box {
        display: flex;
        align-items: center;
        // justify-content: space-around;
        justify-content: flex-end;
        div:hover {
          color: #7c0a03;
          border-color: #7c0a03;
        }
        .add-printer {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 174px;
          height: 52px;
          background: #ffffff;
          border: 1px solid #333333;
          border-radius: 12px;
          font-size: 18px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: 400;
          color: #333333;
          margin-right: 24px;
          cursor: pointer;
        }
        .update-status {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 120px;
          height: 52px;
          background: #ffffff;
          border: 1px solid #333333;
          border-radius: 12px;
          font-size: 18px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: 400;
          color: #333333;
          margin-right: 24px;
          cursor: pointer;
          &:last-child {
            margin-right: 0px;
          }
        }
        .computer {
          margin-right: 24px;
          display: flex;
          justify-content: center;
          align-items: center;
          cursor: pointer;
          width: 138px;
          height: 52px;
          background: #ffffff;
          border: 1px solid #333333;
          border-radius: 12px;
          font-size: 18px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: 400;
          color: #333333;
        }
      }
    }
  }
}
</style>

<style lang="scss">
// ::v-deep{
  .search-date-box {
    width: 100px !important;
    height: 46px !important;
    border-radius: 25px !important;
    box-sizing: border-box;
    padding-left: 20px !important;
    margin-right: 620px;
    
    .el-range-input {
      height: 36px !important;
      line-height: 36px !important;
    }
    
    .el-range-separator {
      line-height: 36px !important;
    }
    
    .el-input__inner {
      height: 36px !important;
      line-height: 36px !important;
    }
  }
// }
</style>